const wsUrl = 'wss://waichi.love:8081/ws/'

// const baseUrl = 'http://localhost:8081'
const baseUrl = 'https://waichi.love:8081'

const request = (options = {}) => {
	// 在这里可以对请求头进行一些设置，例如token
	options.header = {
		"Authorization": uni.getStorageSync('token')
	}
	
	return new Promise((resolve, reject) => {
		uni.request({
			url: baseUrl + options.url || '',
			method: options.type || 'GET',
			data: options.data || {},
			header: options.header || {}
		}).then(res => {
			resolve(res.data);
		}).catch(error => {
			reject(error)
		})
	});
}

const get = (url, data, options = {}) => {
	options.type = 'GET';
	options.data = data;
	options.url = url;
	return request(options)
}

const post = (url, data, options = {}) => {
	options.type = 'POST';
	options.data = data;
	options.url = url;
	return request(options)
}


export default {
	wsUrl,
	baseUrl,
	get,
	post
}